using System.Collections.Generic;
using System.Linq;

namespace Medianamik.Core.Urls
{
    internal class UrlFastDomainDictionary : Dictionary<string, UrlFastDomain>
    {
        public int GetNumberOfDistinctEntries()
        {
            return Values.Sum(domainDictionary => domainDictionary.GetNumberOfDistinctEntries());
        }

        public bool TryGetEntryByPath(string path, out IUrlDictionaryEntry result)
        {
            IUrlDictionaryEntry returnValue = null;

            var searchSuccess = Values.Any(domainDictionary => 
                domainDictionary.TryGetEntryByPath(path, out returnValue));

            result = returnValue;
            
            return searchSuccess;
        }
    }
}